package com.joy.utils;

import java.math.BigDecimal;

/**
 * 数字工具类
 */
public class NumberUtils {
    public static BigDecimal add(BigDecimal a, BigDecimal b) {
        if (a == null) {
            a = BigDecimal.ZERO;
        }
        if (b == null) {
            b = BigDecimal.ZERO;
        }
        return a.add(b);
    }

    public static BigDecimal subtract(BigDecimal a, BigDecimal b) {
        if (a == null) {
            a = BigDecimal.ZERO;
        }
        if (b == null) {
            b = BigDecimal.ZERO;
        }
        return a.subtract(b);
    }

    public static BigDecimal multiply(BigDecimal a, BigDecimal b) {
        if (a == null) {
            a = BigDecimal.ZERO;
        }
        if (b == null) {
            b = BigDecimal.ZERO;
        }
        return a.multiply(b);
    }

    public static BigDecimal divide(BigDecimal a, BigDecimal b) {
        if (a == null) {
            a = BigDecimal.ZERO;
        }
        if (b == null) {
           throw new IllegalArgumentException("除数不能为0");
        }
        return a.divide(b);
    }

    public static String replaceEndZero(String reginCode) {
        reginCode = reginCode.replaceAll("0+$", ""); // 使用正则表达式去除末尾的0
        return reginCode;
    }

    /**
     * 根据传入的数字，返回对应的中文数字
     */
    public static String numberToChinese(long num) {
        return numberToChinese(String.valueOf(num));
    }
    public static String numberToChinese(String numStr) {
        return null;
    }


}
